import re

with open('18号日志.txt', 'r') as file:
    org_data = file.read()

# org_data = ""
# 1. 提取每个 JSON 块
json_blocks = re.findall(r'\{[\s\S]*?\}', org_data)

x_arr = []
y_arr = []
# 2. 从每个 JSON 块提取 x 和 y
for block in json_blocks:
    x_match = re.search(r'"x":\s*([0-9.]+)', block)
    y_match = re.search(r'"y":\s*([0-9.]+)', block)
    if x_match and y_match:
        x = x_match.group(1)
        y = y_match.group(1)
        # print(f"x = {x}, y = {y}")
        x_arr.append(float(x))
        y_arr.append(float(y))

# print(f"x:{x_arr} \n\n\n\n\n\n\n\n\ny:{y_arr}")
# print(len(x_arr))
# 输出到txt文件
with open('output.txt', 'w') as txt_file:
    for x, y in zip(x_arr, y_arr):
        txt_file.write(f"{x},{y}\n")
        